package prolog.terms

import prolog.io.Parser;
import java.util.Iterator;
import prolog.fluents.HashDict;
import prolog.io._;

class Clause(head: Term, body: Term, sym: String) extends Fun(":-", head, body) {
  def this() = this(null, null, null)
  def this(head: Term, body: Term) = this(head, body, null)
  def this(s: String) = {
    this(null, null, s)
    // val C = clauseFromString(s);
    //  this.args = C.args;

  }

  //  def clauseFromString(s: String): Clause = {
  //    return new Parser().clsFromString(s);
  // }

  def checkIfGround(): Unit = {
    ground = false;
    //ground=varsOf().getArity()==0;
  }
  /*
  def toGoal(): Clause = {
    var G = new Clause(Term.varsof(), getHead());
    // G.dict = dict
    return G;
  }
*/
  def getHead(): Term = return args(0).ref
  /**
   * Extracts the body of a clause
   */
  final def getBody(): Term = {
    return args(1).ref;
  }

  /**
   * Variable dictionary
   */
  def dict(): HashDict = null;

  /**
   * Remembers if a clause is ground.
   */
  var ground: Boolean = false;

  /**
   * File name and line where sources start and end (if applicable)
   */
  var fname: String = null;

  var begins_at: Int = 0;

  var ends_at: Int = 0;

  def setFile(fname: String, begins_at: Int, ends_at: Int): Unit = {
    this.fname = fname.intern();
    this.begins_at = begins_at;
    this.ends_at = ends_at;

  }

  /**
   * Checks if a Clause has been proven ground after
   * beeing read in or created.
   */
  def provenGround(): Boolean = {
    ground;
  }
  /**
   * Prints out a clause as Head:-Body
   *
   * private def Clause2String(c: Clause): String = {
   * var h: Term = c.getHead();
   * var t: Term = c.getBody;
   * if (t.isInstanceOf[Conj])
   * // return ([Conj]t).conjToString();
   * return "jeje"
   *
   * // return h + ":-" + ((Conj)t).conjToString();
   * //  return h + ":-" + t;
   * }
   */
}